<template>
	<view class="book-wrapper">
		<view class="box" v-html="list.content">

		</view>
		<!-- 底部 -->
		<view class="footer">
			<view class="box-item">
				<u-icon name="arrow-leftward" color="#333333" size="23" @click="shangyi()"></u-icon>
			</view>
			<view class="box-item">
				<u-icon name="grid" color="#333333" size="23" @click="show = true"></u-icon>
				<view class="i">
					<span style="color: #5ccc84;">{{n}}</span>/{{list.menus.length}}
				</view>
			</view>
			<view class="box-item">
				<u-icon name="arrow-rightward" color="#333333" size="23" @click="xiayi()"></u-icon>
			</view>
		</view>
		<!-- 弹出层 -->
		<u-popup :show="show" closeOnClickOverlay="true" customStyle="{width='40%'}" mode="left" @close="show=false">
			<view class="box">
				<view class="page" v-for="(item,index) in list.menus" :key="index" @click="ce(item.id)">
					<view class="left">00{{index+1}}</view>
					<view class="right">
						<view class="top">{{item.title}} </view>
						<view :class="item.isfree == 1 ? 'bottom' : ''">
							{{item.isfree == 1 ? "免费试看" : ''}}
						</view>
					</view>
				</view>
			</view>
		</u-popup>


	</view>
</template>

<script>
	import {
		detailList
	} from "../api/book.js"
	export default {
		data() {
			return {
				n: 1,
				show: false,
				list: [],
				id: 0,
				bookid: 0
			}
		},
		onLoad(e) {
			this.id = e.id;
			this.bookid = e.book_id
			console.log(e, "EEEEEEEEEEEEEEEEEEE")
			this.getlist()
		},
		methods: {
			//侧边点击
			ce(id) {
				console.log(id, "id")
				this.id = id;
				this.show = false
				this.getlist()
			},
			//上一页
			shangyi() {
				if (this.n <= 1) {
					return
				} else {
					this.n--
					this.list.menus.forEach((item, i) => {
						if (this.n == i - 1) {
							this.id = this.list.menus[this.n - 1].id
							console.log(this.n, this.list.menus[this.n - 1].id);
							this.getlist()
						}
					})
				}
				this.getlist()
			},
			//下一页
			xiayi(id) {
				if (this.n == this.list.menus.length) {
					return
				} else {
					this.n++
					this.list.menus.forEach((item, i) => {
						if (this.n == i - 1) {
							this.id = this.list.menus[this.n - 1].id
							console.log(this.n, this.list.menus[this.n - 1].id);
							this.getlist()
						}
					})
				}
				this.getlist()
			},
			//获取数据
			async getlist() {
				const res = await detailList({
					book_id: this.bookid,
					id: this.id
				});
				console.log(res, "22222222222222222");
				this.list = res.data.data
			},
		}
	}
</script>

<style lang="scss">
	.u-transition {
		overflow: auto !important;
	}

	.book-wrapper {
		width: 100%;

		.box {
			max-height: 100%;
			overflow: auto;

			.page {
				width: 100%;
				height: 150rpx;
				display: flex;
				align-items: center;
				color: #6c757d;

				.left {
					width: 40%;
					height: 100%;
					display: flex;
					justify-content: center;
					font-size: 35rpx;
					align-items: center;
					margin-right: 10rpx;
				}

				.right {
					display: flex;
					width: 100%;
					flex-direction: column;
					font-size: 30rpx;

					.bottom {
						color: #dc3545;
						border: 1px solid #dc3545;
						border-radius: 30rpx;
						width: 100rpx;
						height: 30rpx;
						display: flex;
						font-size: 25rpx;
						justify-content: center;
						align-items: center;
						margin-top: 10rpx;
					}
				}
			}
		}



		.box {
			width: 100%;
			padding: 20rpx;
			box-sizing: border-box;
			font-size: 40rpx;
		}

		.footer {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 100rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.box-item {
				width: 33.3%;
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-size: 35rpx;
			}
		}
	}
</style>
